var a = require("../../../@babel/runtime/helpers/objectSpread2"), t = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Page({
    data: {
        form: {
            name: "",
            sex: 0,
            birthday: "",
            detailedAddress: "",
            dataTime: "请选择",
            text: "",
            address: "",
            field: "",
            nickname: ""
        },
        districtName: "",
        district: "",
        sexShow: !1,
        birthdayShow: !1,
        showAdd: !1,
        fixedDiyField: "",
        diyform: "",
        registerBasicInfo: {},
        nameOfTheMall: "",
        userProtocol: "",
        diyField: "",
        diyStatus: 0,
        changeNickname: !1,
        changePicture: !1,
        isShowAddress: "",
        selectAddressData: [],
        provinceData: [],
        pickerValue: [ 0, 0, 0 ],
        districtData: [],
        minDate: new Date(1900, 0, 1).getTime(),
        maxDate: new Date(2025, 0, 1).getTime(),
        currentDate: new Date().getTime(),
        addressObject: {
            province: "",
            province_name: "",
            city: "",
            city_name: "",
            area: "",
            area_name: ""
        },
        member_id: "",
        info: {},
        form_id: "",
        fileList: [ {
            url: "",
            isImage: !0
        } ],
        orderLocationObj: {
            positioning_success: 0,
            register_province: "",
            register_city: ""
        },
        sexLIst: [ {
            value: "男",
            url: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/debt/manNo.png",
            checkedUrl: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/debt/manYes.png",
            checked: !1
        }, {
            value: "女",
            url: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/debt/womenNo.png",
            checkedUrl: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/debt/womenYes.png",
            checked: !1
        } ],
        customFormID: "",
        subject: "",
        child: ""
    },
    onLoad: function(a) {
        this.essentialInformation();
        var t = wx.getStorageSync("yz_basic_info").theme_color;
        this.setData({
            subject: t
        });
    },
    onReady: function() {},
    onShow: function() {
        this._initAddressInfo();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    sexSwitch: function(a) {
        var e = this;
        this.data.sexLIst.forEach(function(i, s) {
            var d = "sexLIst[".concat(s, "].checked");
            a.currentTarget.dataset.index == s ? (e.setData(t({}, d, !0)), 1 == a.currentTarget.dataset.index ? e.setData({
                "form.sex": 2
            }) : e.setData({
                "form.sex": 1
            })) : e.setData(t({}, d, !1));
        });
    },
    sexPopup: function() {
        this.setData({
            sexShow: !this.data.sexShow
        });
    },
    birthdayPopup: function() {
        this.setData({
            birthdayShow: !this.data.birthdayShow
        });
    },
    formatDate: function(a) {
        return a = new Date(a), "".concat(a.getYear() + 1900, "-").concat(a.getMonth() + 1, "-").concat(a.getDate());
    },
    afterRead: function(t) {
        var i = this;
        console.log("图片", t);
        var s = e.getNetAddresss("upload.uploadPic");
        wx.uploadFile({
            url: s,
            filePath: t.detail.avatarUrl,
            name: "file",
            formData: null,
            success: function(e) {
                var s = JSON.parse(e.data);
                i.setData({
                    "fileList[0]": a(a({}, t.detail.avatarUrl), {}, {
                        url: s.data.img_url
                    }),
                    "form.avatar": s.data.img
                }), console.log(i.data.form.avatar, i.data.fileList[0].url);
            }
        });
    },
    onConfirm: function(a) {
        this.onClose(), this.setData({
            "form.birthday": this.formatDate(a.detail)
        });
    },
    onClose: function() {
        this.setData({
            birthdayShow: !1
        });
    },
    _initAddressInfo: function() {
        var a = this;
        wx.getStorage({
            key: "provinceData",
            success: function(t) {
                console.log("地址信息准备就绪"), a._getProvinceData();
            },
            fail: function(t) {
                console.log("省fail"), e._getNetWork({
                    url: e.getNetAddresss("member.member-address.address"),
                    success: function(t) {
                        var e = t.data, i = e.data.province, s = e.data.city, d = e.data.district;
                        wx.setStorage({
                            key: "provinceData",
                            data: i
                        }), wx.setStorage({
                            key: "cityData",
                            data: s
                        }), wx.setStorage({
                            key: "districtData",
                            data: d
                        }), a._initAddressInfo();
                    },
                    fail: function(a) {},
                    state: !0
                });
            }
        });
    },
    _initDistrict: function(a, t) {
        if (!e._isTextEmpty(a)) return e._isTextEmpty(a.myform.form) || this.setData({
            isShowAddress: 1 == a.myform.base.address
        }), void this.setData({
            "addressObject.province": a.province,
            "addressObject.province_name": a.province_name,
            "addressObject.city": a.city,
            "addressObject.city_name": a.city_name,
            "addressObject.area": a.area,
            "addressObject.area_name": a.area_name,
            districtName: a.province_name + " " + a.city_name + " " + a.area_name,
            "addressObject.address": a.address
        });
        e._isTextEmpty(t) || (this.setData({
            "addressObject.province": t.itemValue1,
            "addressObject.province_name": t.itemName1,
            "addressObject.city": t.itemValue2,
            "addressObject.city_name": t.itemName2,
            "addressObject.area": t.itemValue3,
            "addressObject.area_name": t.itemName3
        }), this.setData({
            districtName: t.itemName1 + " " + t.itemName2 + " " + t.itemName3
        }));
    },
    _getProvinceData: function() {
        var a = this;
        wx.getStorage({
            key: "provinceData",
            success: function(t) {
                console.log("省读取成功", t.data), a.setData({
                    provinceData: t.data
                }), a.setData({
                    "selectAddressData[0].name": t.data[a.data.pickerValue[0]].areaname,
                    "selectAddressData[0].id": t.data[a.data.pickerValue[0]].id,
                    "selectAddressData[0].index": a.data.pickerValue[0]
                }), a._getCityData();
            }
        });
    },
    _getCityData: function() {
        var a = this.data.selectAddressData[0];
        console.log("城市", "_data", a);
        var t = this;
        wx.getStorage({
            key: "cityData",
            success: function(e) {
                console.log("城市读取成功", e);
                for (var i = [], s = 0; s < e.data.length; s++) e.data[s].parentid == a.id && i.push(e.data[s]);
                console.log("城市数据筛选", i), t.setData({
                    cityData: i
                }), t.setData({
                    "selectAddressData[1].name": i[t.data.pickerValue[1]].areaname,
                    "selectAddressData[1].id": i[t.data.pickerValue[1]].id,
                    "selectAddressData[1].index": t.data.pickerValue[1]
                }), t._getDistrictData();
            }
        });
    },
    _getDistrictData: function() {
        var a = this.data.selectAddressData[1];
        console.log("地区", "_data", a), console.log(a);
        var t = this;
        wx.getStorage({
            key: "districtData",
            success: function(e) {
                console.log("地区读取成功");
                for (var i = [], s = 0; s < e.data.length; s++) e.data[s].parentid == a.id && i.push(e.data[s]);
                console.log("地区数据筛选", i), t.setData({
                    districtData: i
                }), console.log("districtData", i), t.setData({
                    "selectAddressData[2].name": i[t.data.pickerValue[2]].areaname,
                    "selectAddressData[2].id": i[t.data.pickerValue[2]].id,
                    "selectAddressData[2].index": t.data.pickerValue[2]
                }), console.log("over", t.data.selectAddressData);
            }
        });
    },
    showAddBtn: function() {
        this.setData({
            showAdd: !0
        });
    },
    _closeDateLw: function() {
        this.setData({
            showAdd: !1
        });
    },
    bindChange: function(a) {
        var t = a.detail.value;
        this.data.pickerValue[0] != t[0] && (t[1] = 0, t[2] = 0), this.data.pickerValue[1] != t[1] && (t[2] = 0), 
        this.setData({
            "pickerValue[0]": t[0],
            "pickerValue[1]": t[1],
            "pickerValue[2]": t[2]
        }), this._initAddressInfo();
    },
    resultAdd: function() {
        var a = this.data.selectAddressData, t = {
            itemValue1: a[0].id,
            itemName1: a[0].name,
            itemValue2: a[1].id,
            itemName2: a[1].name,
            itemValue3: a[2].id,
            itemName3: a[2].name
        };
        this._initDistrict("", t), this._closeDateLw();
    },
    getUserProfileTap: function() {
        var a = this;
        wx.getUserProfile({
            desc: "获取用户信息",
            success: function(t) {
                console.log("info:", t);
                var e = {
                    nickName: t.userInfo.nickName,
                    avatarUrl: t.userInfo.avatarUrl,
                    gender: t.userInfo.gender
                };
                a.setData({
                    info: e
                }), a.updateInfo();
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    choose: function(a) {
        var t = this, i = e.getNetAddresss("upload.uploadPic");
        wx.uploadFile({
            url: i,
            filePath: a.detail.avatarUrl,
            name: "file",
            success: function(a) {
                var e = JSON.parse(a.data);
                1 == e.result ? t.setData({
                    "form.avatar": e.data.img_url
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            }
        });
    },
    onChange: function(a) {
        var e = a.currentTarget.dataset, i = "";
        if ("custom" == e.type) return i = "diyField.form[".concat(e.index, "].value"), 
        void this.setData(t({}, i, a.detail));
        "fixed" == e.type ? this.setData({
            "form.field": a.detail
        }) : (i = "form.".concat(e.typevalue), console.log(i, a.detail), this.setData(t({}, i, a.detail)));
    },
    updateInfo: function() {
        var a = this, t = e.getNetAddresss("member.member-update.index");
        e._postNetWork({
            url: t,
            data: {
                type: 2,
                info: a.data.info
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? (wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1e3
                }), a.essentialInformation()) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    essentialInformation: function() {
        var a = this, i = e.getNetAddresss("member.member-info.user-info");
        e._getNetWork({
            url: i,
            data: {
                basic_info: 1
            },
            success: function(e) {
                var i, s, d, r, o, n = e.data;
                1 == n.result ? (n.data.basic_info.forEach(function(e, i) {
                    var s = "registerBasicInfo.".concat(e.field);
                    a.setData(t({}, s, e));
                }), a.setData({
                    "form.nickname": n.data.nickname,
                    "form.avatar": n.data.avatar,
                    "fileList[0].url": n.data.avatar_image,
                    diyform: n.data.diy_form,
                    nameOfTheMall: n.data.name,
                    changeNickname: n.data.can_update_nickname,
                    diyField: n.data.diy_field,
                    fixedDiyField: n.data.fixed_diy_field,
                    changePicture: n.data.can_update_avatar,
                    "form.name": a.data.registerBasicInfo.name.value,
                    "form.sex": a.data.registerBasicInfo.gender.value,
                    "form.address": a.data.registerBasicInfo.address.value,
                    "form.detailedAddress": a.data.registerBasicInfo.address.value.address,
                    diyStatus: n.data.diy_form.status,
                    customFormID: {
                        form_id: n.data.diy_form.id
                    }
                }), "" != (null === (i = a.data.registerBasicInfo) || void 0 === i || null === (s = i.birthday) || void 0 === s || null === (d = s.value) || void 0 === d ? void 0 : d.birthyear) && a.setData({
                    "form.birthday": a.data.registerBasicInfo.birthday.value.birthyear + "-" + a.data.registerBasicInfo.birthday.value.birthmonth + "-" + a.data.registerBasicInfo.birthday.value.birthday,
                    currentDate: new Date(a.data.registerBasicInfo.birthday.value.birthyear, a.data.registerBasicInfo.birthday.value.birthmonth - 1, a.data.registerBasicInfo.birthday.value.birthday).getTime()
                }), "" != (null === (r = a.data.registerBasicInfo.address) || void 0 === r || null === (o = r.value) || void 0 === o ? void 0 : o.province_name) && a.setData({
                    districtName: a.data.registerBasicInfo.address.value.province_name + "  " + a.data.registerBasicInfo.address.value.city_name + "  " + a.data.registerBasicInfo.address.value.area_name
                }), 2 == a.data.registerBasicInfo.gender.value && a.setData({
                    "sexLIst[0].checked": !1,
                    "sexLIst[1].checked": !0
                }), a.data.fixedDiyField.length > 0 && a.setData({
                    "form.field": n.data.fixed_diy_field[0].value
                }), 1 == a.data.diyStatus && a.setData({
                    child: a.selectComponent(".dsfrom")
                })) : wx.showToast({
                    icon: "none",
                    title: n.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    modifyingUserInformation: function() {
        var a = this;
        if (this.data.registerBasicInfo.name && this.data.registerBasicInfo.name.show && 1 == this.data.registerBasicInfo.name.must && e._isTextEmpty(this.data.form.name)) wx.showToast({
            icon: "none",
            title: "请填写姓名",
            duration: 1500
        }); else if (console.log(this.data.form.sex, "性别"), this.data.registerBasicInfo.gender && this.data.registerBasicInfo.gender.show && 1 == this.data.registerBasicInfo.gender.must && e._isTextEmpty(this.data.form.sex)) wx.showToast({
            icon: "none",
            title: "请选择性别",
            duration: 1500
        }); else if (this.data.registerBasicInfo.birthday && this.data.registerBasicInfo.birthday.show && 1 == this.data.registerBasicInfo.birthday.must && e._isTextEmpty(this.data.form.birthday)) wx.showToast({
            icon: "none",
            title: "请选择生日",
            duration: 1500
        }); else if (this.data.registerBasicInfo.address && this.data.registerBasicInfo.address.show && 1 == this.data.registerBasicInfo.address.must && e._isTextEmpty(this.data.districtName)) wx.showToast({
            icon: "none",
            title: "请填写详细地址",
            duration: 1500
        }); else {
            if (this.data.fixedDiyField.length > 0) {
                var t = !0, i = "";
                if (this.data.fixedDiyField.forEach(function(e, s) {
                    "" == a.data.form.field && 1 == e.must && (i = "请填写" + e.name, t = !1);
                }), !t) return void wx.showToast({
                    icon: "none",
                    title: i,
                    duration: 1500
                });
            }
            if (!e._isTextEmpty(this.data.diyField) && this.data.diyField.form.length > 0 && 1 == this.data.diyField.form_open) {
                var s = !0, d = "";
                if (this.data.diyField.form.forEach(function(a, t) {
                    e._isTextEmpty(a.value) && (d = "请填写" + a.name, s = !1);
                }), !s) return void wx.showToast({
                    icon: "none",
                    title: d,
                    duration: 1500
                });
            }
            if (1 != this.data.diyStatus || (this.data.child.validation(), console.log(this.data.child.data.isValidation), 
            this.data.child.data.isValidation)) {
                var r = {
                    avatar: this.data.form.avatar,
                    nickname: this.data.form.nickname,
                    name: this.data.form.name,
                    gender: this.data.form.sex,
                    birthday: this.data.form.birthday,
                    custom_value: this.data.form.field
                };
                if (e._isTextEmpty(this.data.form.address.province) || e._isTextEmpty(this.data.form.address.city) || (this.data.form.address.address = this.data.form.detailedAddress, 
                r.address = this.data.form.address), this.data.registerBasicInfo.address.show && "" != this.data.addressObject.province_name && "" != this.data.addressObject.city_name && (this.setData({
                    "addressObject.address": this.data.form.detailedAddress
                }), r.address = this.data.addressObject), this.data.diyField.form.length > 0) {
                    var o = {};
                    this.data.diyField.form.forEach(function(a, t) {
                        o[a.field] = a.value, console.log("加值", a);
                    }), r.customDatas = o;
                }
                console.log("json", r);
                var n = e.getNetAddresss("member.member-info.user-info-save");
                e._postNetWork({
                    url: n,
                    data: r,
                    success: function(t) {
                        var e = t.data;
                        1 == e.result ? 1 == a.data.diyStatus ? (a.data.child.submit(), wx.navigateBack({
                            delta: 1
                        })) : (wx.navigateBack({
                            delta: 1
                        }), wx.showToast({
                            icon: "success",
                            title: "提交成功",
                            duration: 1500
                        })) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    },
                    fail: function(a) {
                        console.log(a);
                    }
                });
            }
        }
    },
    addressToDealWith: function(a) {
        var t = {};
        return t.province = a[0].id, t.city = a[1].id, t.area = a[2].id, t.province_name = a[0].name, 
        t.city_name = a[1].name, t.address = this.info_form.address, t;
    },
    postDiy: function(a) {
        var t = this, i = {
            form_data: a.detail,
            form_id: this.data.form_id,
            form_type: "register"
        }, s = e.getNetAddresss("plugin.diyform.api.diy-form.save-diy-form-data");
        e._postNetWork({
            url: s,
            showToastIn: !1,
            data: i,
            success: function(a) {
                var e = a.data;
                1 == e.result ? wx.showToast({
                    title: "绑定成功",
                    icon: "none",
                    duration: 1500,
                    success: function() {
                        setTimeout(function() {
                            t.gotourl();
                        }, 1500);
                    }
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {}
        });
    },
    onShareAppMessage: function() {}
});